package top.jacktgq.hsp.netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Author CandyWall
 * @Date 2020/11/12--15:28
 * @Description 使用Netty构建一个Http服务器
 */
public class TestHttpServer {
    public static void main(String[] args) {
        EventLoopGroup bossGroup = null;
        EventLoopGroup workerGroup = null;
        try {
            bossGroup = new NioEventLoopGroup();
            workerGroup = new NioEventLoopGroup();
            ServerBootstrap serverBootstrap = new ServerBootstrap();

            serverBootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new top.jacktgq.hsp.netty.http.TestHttpServerinitializer());
            //谷歌浏览器，QQ浏览器，MicroSoft Edge浏览器认为6666-6669端口有风险，所以给封了
            //用这几款浏览器的时候需要换其他端口，而360浏览器没有封，可以继续使用这些端口
            ChannelFuture channelFuture = serverBootstrap.bind(8888).sync();

            channelFuture.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }

    }
}
